package lanou.autohome.recommend.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.basetool.NetTool;
import lanou.autohome.R;
import lanou.autohome.recommend.beans.NewsBean;

/**
 * Created by dllo on 16/8/16.
 */
public class NewsAdapter extends BaseAdapter {

    private static final int TYPE_THREE = 1;
    private static final int TYPE_ONE = 0;
    private Context mcontext;
    private NewsBean newsBean;

    public NewsAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setNewsBean(NewsBean newsBean) {
        this.newsBean = newsBean;
    }

    @Override
    public int getCount() {
        return newsBean.getResult().getNewslist().size();
    }

    @Override
    public Object getItem(int i) {
        return newsBean.getResult().getNewslist().get(i);
    }


    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
//        switch (i) {
//            case TYPE_ONE:
                if (convertView == null) {
                    convertView = LayoutInflater.from(mcontext).inflate(R.layout.item_recommend_news, null);
                    viewHolder = new ViewHolder(convertView);
                    convertView.setTag(viewHolder);
                } else {
                    viewHolder = (ViewHolder) convertView.getTag();
                }
                NewsBean.ResultBean.NewslistBean bean = newsBean.getResult().getNewslist().get(i);
                viewHolder.title.setText(bean.getTitle());
                viewHolder.time.setText(bean.getTime());
                viewHolder.replycount.setText(bean.getReplycount()+ "评论");

                NetTool netTool = new NetTool();
                netTool.getImage(bean.getSmallpic(), viewHolder.smallpic);

        return convertView;
    }

    public class ViewHolder {

        ImageView smallpic;
        TextView title;
        TextView time;
        TextView replycount;

        private ViewHolder(View convertView) {
            super();
            smallpic = (ImageView) convertView.findViewById(R.id.smallpic_recommend_news_item);
            title = (TextView) convertView.findViewById(R.id.title_recommend_news_item);
            time = (TextView) convertView.findViewById(R.id.time_recommend_news_item);
            replycount = (TextView) convertView.findViewById(R.id.replycount_recommend_news_item);

        }
    }

}
